package com.daisuxia.back.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daisuxia.back.dao.IRiskCreditUsrDao;
import com.daisuxia.risk.pojo.RiskCreditUser;
import com.daisuxia.risk.pojo.RiskRuleCal;
import com.daisuxia.web.test.StringUtil;

@Service("riskUserService")
public class RiskUserService implements IRiskUserService {

	@Autowired
	IRiskCreditUsrDao riskCreditUsrDao;

	public RiskCreditUser findRiskCreditUserByAssetsId(String assetsId) {
		return riskCreditUsrDao.findByAssetsId(assetsId);
	}

	public List<RiskRuleCal> findRiskRuleCalByAssetsId(String assetsId) {
		List<RiskRuleCal> list = new ArrayList<RiskRuleCal>();
		String riskCalSuf = riskCreditUsrDao.findSuf(assetsId);
		if (StringUtils.isNotBlank(riskCalSuf)) {
			HashMap<String, String> params = new HashMap<String, String>();
			params.put("riskCalSuf", riskCalSuf);
			params.put("assetsId", assetsId);
			list = riskCreditUsrDao.findRiskRuleCalByAssetsId(params);
		}
		return list;
	}

	@Override
	public List<RiskRuleCal> findRiskRuleCalByUserId(String userId) {
		List<RiskRuleCal> list = new ArrayList<RiskRuleCal>();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
		String date=sdf.format(new Date());
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("riskCalSuf", date);
		params.put("userId", userId);
		list = riskCreditUsrDao.findRiskRuleCalByUserId(params);
		return list;
	}
	
}
